import { createStore, applyMiddleware, compose } from 'redux';
import createSagaMiddleware from 'redux-saga';
// Logger with default options
import logger from 'redux-logger';

import modules from './modules'; // 引用具体reducer模块

const isDev = process.env.NODE_ENV === 'development';
// create the saga middleware
export const sagaMiddleware = createSagaMiddleware();

const devTools = isDev && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__;
const composeEnhancers = devTools || compose;
const middlewares = [sagaMiddleware, logger];

const configure = () =>
    createStore(modules.reducer, composeEnhancers(applyMiddleware(...middlewares)));

export default configure;
